<template>
  <div class="tableSubscribeRanking">
    <x-header class="header" :left-options="{showBack: showHeaderBack,preventGoBack:true}" @on-click-back="goToPage" ref="header">台位订位排行</x-header>
    <div class="topHolder"></div>
    <card class="gridDisplay">
      <div class="card-padding" slot="content" style="padding-top: 0;">
        <div class="filterArea dateFilter" ref="filterArea">
          <group-title style="text-align: center;">当前显示日期：{{choosenDate}}<br/></group-title>
          <x-button :show-loading="loadingStatus" :disabled="loadingStatus" @click.native="changeDate(1)" class="inlineBtn">今日</x-button>
          <x-button :show-loading="loadingStatus" :disabled="loadingStatus" @click.native="changeDate(2)" class="inlineBtn">昨日</x-button>
          <a v-if="loadingStatus" class="datePicker"><i class="iconfont icon-rilicalendar107"></i></a>
          <datetime v-else v-model="choosenDate" :start-date="startDate" :end-date="endDate" @on-confirm="changeDate(0)" class="datePicker">
            <i class="iconfont icon-rilicalendar107"></i>
          </datetime>
        </div>
      </div>
    </card>
    <group title="房台类型明细：">
      <x-table :cell-bordered="false">
        <thead>
        <tr style="background-color: #F7F7F7">
          <th width="20%">排位</th>
          <th width="45%">房台号码</th>
          <th width="25%">订位次数</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(item,index) in rankingList" :key="index">
          <td v-text="index + 1"></td>
          <td v-html="item.ROOM_PLATFORM_TYPE + '(' + item.AREA + ') - ' + item.NUMBER"></td>
          <td v-text="item.number"></td>
        </tr>
        <tr v-if="rankingList.length <= 0">
          <td colspan="4">
            <div class="listNoItem">暂无排行明细</div>
          </td>
        </tr>
        </tbody>
      </x-table>
    </group>
  </div>
</template>

<script>
  import {XButton, Card, Group, XTable, Datetime, GroupTitle, dateFormat } from 'vux'
  import {getTableSubscribeRanking} from "../../api";
  import {message} from "../../common/util";

  export default {
    name:'tableSubscribeRanking',
    data(){
      return{
        showHeaderBack:this.GLOBAL.showHeaderBack,
        loadingStatus:true,
        choosenDate:dateFormat(new Date(), 'YYYY-MM-DD'),
        startDate:'2019-01-01',
        endDate:dateFormat(new Date(), 'YYYY-MM-DD'),
        rankingList:[]
      }
    },
    components:{
      XButton,
      Card,
      Group,
      XTable,
      Datetime,
      GroupTitle
    },
    computed:{
    },
    methods:{
      goToPage(){
        this.$router.push({path:'/'})
      },
      changeDate(value){
        console.log(value)
        switch (value) {
          case 1:this.choosenDate = dateFormat(new Date(), 'YYYY-MM-DD');break;
          case 2:this.choosenDate = dateFormat(new Date().setDate(new Date().getDate()-1), 'YYYY-MM-DD');break;
          default: break;
        }
        console.log(this.choosenDate)
        this.refreshPage()
      },
      refreshPage(){
        this.loadingStatus = true
        getTableSubscribeRanking(this.choosenDate).then((res)=>{
          if(res.status == 'success'){
            this.rankingList = res.data
            this.rankingList.sort(function(item1,item2){
              if(item1.number > item2.number){
                return -1;
              }else if(item1.number < item2.number){
                return 1;
              }
              return 0;
            })
          }else if(res.status == 'error') {
            message({message:res.msg,type:'error'})
            console.log('getTableSubscribeRanking error info:', res.msg)
          }
          this.loadingStatus = false
        }).catch((err)=>{console.log('getTableSubscribeRanking catch info:',err)})
      }
    },
    mounted(){
      this.refreshPage()
      this.$store.commit('updateLoadingStatus',{isLoading:false})
    }
  }
</script>

<style lang="scss">
  .tableSubscribeRanking{
    .gridDisplay{
      .filterArea{
        &.dateFilter{
          margin-bottom: 0.5rem;
          .datePicker{
            float: right;padding: 0;
            &.weui-cell:before{border-top: none;}
            i{font-size: 2rem;color:#535353;}
          }
        }
        .filterItem{margin-top: 0.5rem;}
      }
    }
  }
</style>
